package king.dominic.jlibrary.util;

import android.webkit.WebView;

/**
 * Created by king on 2017/4/6.
 * JSInterface
 */

public class JSInterface {
    public static void callJavascriptMethod(WebView webView, String methodName, String... params) {
        StringBuilder builder = new StringBuilder("");
        builder.append("javascript:");
        builder.append(methodName);
        builder.append("(");
        if (params != null && params.length > 0) {
            for (String param : params) {
                builder.append("'");
                builder.append(param);
                builder.append("'");
                builder.append(",");
            }
            builder.delete(builder.length() - 1, builder.length());
        }
        builder.append(")");
        webView.loadUrl(builder.toString());
    }
}
